"""
用户数据模型
"""
from sqlalchemy import Column, String, Boolean, Text
from sqlalchemy.orm import relationship
from models.base import BaseModel


class User(BaseModel):
    """用户模型"""
    __tablename__ = "users"
    
    username = Column(String(50), unique=True, nullable=False, comment="用户名")
    password_hash = Column(String(255), nullable=False, comment="密码哈希")
    email = Column(String(100), comment="邮箱")
    full_name = Column(String(100), comment="姓名")
    role = Column(String(20), default="operator", comment="角色")
    is_active = Column(Boolean, default=True, comment="是否激活")
    avatar = Column(String(255), comment="头像URL")
    phone = Column(String(20), comment="电话号码")
    department = Column(String(100), comment="部门")
    description = Column(Text, comment="用户描述")
    
    # 关联关系
    handled_alerts = relationship("Alert", back_populates="handler")
    
    def __repr__(self):
        return f"<User(id={self.id}, username='{self.username}', role='{self.role}')>"